package cn.bytecollege.controller;

import cn.bytecollege.constant.Resource;
import cn.bytecollege.entity.UserManage;
import cn.bytecollege.service.RoomService;
import cn.bytecollege.service.UserMessageService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author LH
 * @time 2021-10-19 14:46
 */
@WebServlet(name = "UserMessageFindController", value = "/userMessageFind")
public class UserMessageFindController extends HttpServlet {
    private UserMessageService userMessageService=null;
    private RoomService roomService=null;
    public UserMessageFindController(){
        roomService=new RoomService();
        userMessageService=new UserMessageService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id=request.getParameter("id");
        Integer userMessageId=Integer.valueOf(id);
        UserManage userManage=userMessageService.findById(userMessageId);
        roomService.updateRoomStateTo0(userManage.getRoomId());
        request.setAttribute("userManage",userManage);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/userMessageChange.jsp")
                .forward(request,response);
    }
}
